{$CLEO .cs}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "Drop Weapons Like In GTA IV"

// By ArtemQa146

const
    Obj = 0@
    Model_Id = 6@
    Weapon_Render = 7@
    Heavy = 8@
    Key_Drop_Enable = 31@
    Key_1 = 30@
    Key_2 = 29@
    Anim_Speed = 28@
    Anim_Speed_H = 27@
    find = 26@
    Ammo_left = 25@
    Ped_bone = 24@
    Damager_1 = 23@
    Type_1 = 22@
    Bone_1 = 21@
    Intensity_1 = 20@
    Ped_damage = 19@
    Percent_hand_drop = 18@
    Drop_From_Hand = 17@
    Key_3 = 16@
    Mode = 15@
    mode_bullet_zero = 9@
end

0AF0: Key_Drop_Enable = read_int_from_ini_file "cleo\Drop Weapons.ini" section "Drop Key" key "Enable"
0AF0: Key_1 = read_int_from_ini_file "cleo\Drop Weapons.ini" section "Drop Key" key "Key 1"
0AF0: Key_2 = read_int_from_ini_file "cleo\Drop Weapons.ini" section "Drop Key" key "Key 2"
0AF2: Anim_Speed = read_float_from_ini_file "cleo\Drop Weapons.ini" section "Settings" key "Animation Speed"
0AF2: Anim_Speed_H = read_float_from_ini_file "cleo\Drop Weapons.ini" section "Settings" key "Animation Speed Heavy"
0AF0: Percent_hand_drop = read_int_from_ini_file "cleo\Drop Weapons.ini" section "Settings" key "Percent Drop From Hand"
0AF0: Drop_From_Hand = read_int_from_ini_file "cleo\Drop Weapons.ini" section "Settings" key "Drop From Hand"
0AF0: Key_3 = read_int_from_ini_file "cleo\Drop Weapons.ini" section "Drop Key" key "Take a weapon key"
0AF0: Mode = read_int_from_ini_file "cleo\Drop Weapons.ini" section "Settings" key "Mode"
0AF0: mode_bullet_zero = read_int_from_ini_file "cleo\Drop Weapons.ini" section "Settings" key "Drop Weapon when no bullets"

if Drop_From_Hand == 1
then set_script_event_char_damage 1 label @Damage var_char Ped_damage
end

while true
wait 0
    if
        player.Defined(0)
    then
        if Mode == 0
        then gosub @PickUp
        end
        if Drop_From_Hand == 1
        then gosub @Ped_Weapon
        end
        0470: 1@ = actor $PLAYER_ACTOR current_weapon
        if
            1@ > 0 //     
        then
        
            4@ = false //  
        
            if or
                0118:   actor $PLAYER_ACTOR dead
                00DF:   actor $PLAYER_ACTOR driving
                0741:   actor $PLAYER_ACTOR busted
            then
                continue
            end
            
            //    
            if and
                not is_char_using_gun $PLAYER_ACTOR
                Key_Drop_Enable == 1
            then
                if and
                    0AB0:   is_key_pressed Key_1
                    0AB0:   is_key_pressed Key_2
                    03EE:   player $PLAYER_CHAR controllable
                then
                    4@ = true
                end
            end
            
            //    
            041A: 2@ = actor $PLAYER_ACTOR weapon 1@ ammo
            if and
                mode_bullet_zero == 1
                2@ < 1 // 
            then
                0470: 1@ = actor $PLAYER_ACTOR current_weapon
                0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 2@
                0E89: get_weaponinfo_fire_type 2@ store_to 2@
                if or
                    2@ == 1 // 
                    1@ == 41 // #spraycan
                    1@ == 42 // #fire_ex
                    1@ == 37 // #flame
                    1@ == 38 // #minigun
                then
                    if
                        not 1@ == 34 // #sniper
                    then
                        4@ = true
                    end
                end
            end
            
            //      true
            if
                4@ == true
            then
                041A: Ammo_left = $PLAYER_ACTOR pedweapon 1@ ammo
                017B: set_actor $PLAYER_ACTOR weapon 1@ ammo_to 1 //      
                0881: set_player $PLAYER_CHAR able_to_shoot_weapons 0
                0992: set_player $PLAYER_CHAR weapons_scrollable 0
            
                0781: get_weapon_with_ID 1@ model_to Model_Id
                model.Load(Model_Id)
                038B: load_requested_models
                0E2E: create_render_object_to_char_bone $PLAYER_ACTOR model Model_Id bone 24 offset 0 0 0 rotation 0 0 0 store_to Weapon_Render //     
                
                Heavy = false
                
                0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 2@
                0E89: get_weaponinfo_fire_type 2@ store_to 2@
                if or
                    not 2@ == 1
                    1@ == 38 // #minigun
                then
                    Heavy = true //  
                end

                01B9: set_actor $PLAYER_ACTOR armed_weapon_to 0 //    ,    
                0555: remove_weapon 1@ from_actor $PLAYER_ACTOR
            
                repeat
                wait 0
                04ED: load_animation  "DropWeapons"
                until 04EE:   animation "DropWeapons" loaded
            
                0E97: clear_char_secondary_tasks $PLAYER_ACTOR
                if
                    Heavy == true
                then
                    0AD3: 10@v = string_format "DropWeaponsH"
                    4@ = 0.90
                    0087: 5@ = Anim_Speed_H // (float)
                else
                    0AD3: 10@v = string_format "DropWeapons"
                    4@ = 0.90
                    0087: 5@ = Anim_Speed // (float)
                end

                0A1A: actor $PLAYER_ACTOR perform_walk_animation 10@v IFP "DropWeapons" framedelta 6.0 loopA 0 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                04EF: release_animation "DropWeapons"
                wait 100

                repeat
                wait 0
                    if
                        0611:   actor $PLAYER_ACTOR performing_animation 10@v
                    then
                        0393: actor $PLAYER_ACTOR perform_animation 10@v at 5@ times_normal_rate
                        0613: 3@ = actor $PLAYER_ACTOR animation 10@v time
                    else
                        break
                    end
                until 0035:   3@ >= 4@  // (float)
                
                0881: set_player $PLAYER_CHAR able_to_shoot_weapons 1
                0992: set_player $PLAYER_CHAR weapons_scrollable 1
                
                0E2F: delete_render_object Weapon_Render
                
                if and
                    Ammo_left > 0
                    Mode == 1
                then
                
                    04A5: get_dead_actor_pickup_coords $PLAYER_ACTOR store_to 3@ 4@ 5@
                    04C4: store_coords_to 3@ 4@ 2@ from_actor $PLAYER_ACTOR with_offset 2.5 0.6 0.0
                    032B: 1@ = create_weapon_pickup Model_Id group 4 ammo Ammo_left at 3@ 4@ 5@
                    
                else
                
                    0208: 10@ = random_float_in_ranges 0.9 1.2
                    0208: 11@ = random_float_in_ranges 0.0 0.5
                    04C4: store_coords_to 3@ 4@ 5@ from_actor $PLAYER_ACTOR with_offset 10@ 11@ 0.1
                    10@ += 0.13
                    11@ += 0.03
                    0E01: create_object_no_save Model_Id at 3@ 4@ 5@ offset 0 ground 0 to Obj
                    0172: 1@ = actor $PLAYER_ACTOR Z_angle
                    0453: set_object Obj XY_rotation 270.0 0.0 angle 1@
                    05A1: set_object Obj rotation_velocity_about_an_axis 5.0 5.0 0.0 through_center_of_body
                    04C4: store_coords_to 3@ 4@ 5@ from_actor $PLAYER_ACTOR with_offset 10@ 11@ 0.05
                    0815: put_object Obj at 3@ 4@ 5@  and_keep_rotation
                    timera = 0
                    
                    if   Ammo_left > 0 //if weapon has ammo can pickable
                    then gosub @SetAmmo
                    end
                    
                    repeat
                    wait 0
                    0400: store_coords_to 1@ 2@ 3@ from_object Obj with_offset 0.0 0.0 0.0
                    02CE: 1@ = ground_z_at 1@ 2@ 3@
                    0063: 3@ -= 1@  // (float)
                    if
                        3@ <= 0.2
                    then
                        0176: 1@ = object Obj Z_angle
                        0453: set_object Obj XY_rotation 270.0 0.0 angle 1@
                        0382: set_object Obj collision_detection 0
                        0400: store_coords_to 1@ 2@ 3@ from_object Obj with_offset 0.0 0.0 0.0
                        02CE: 3@ = ground_z_at 1@ 2@ 3@
                        3@ += 0.06
                        01BC: put_object Obj at 1@ 2@ 3@
                        break
                    end
                    until timera > 2000
                    01C4: remove_references_to_object Obj // This object will now disappear when the player looks away
                    
                end
                
                model.Destroy(Model_Id)
                
            end
        end
    end
end

:SetAmmo
0A98: 1@ = Obj objstruct
0E28: write_struct 1@ offset 0x11 size 2 value Ammo_left //0xBC4 = [word] Free Slot 1
0E28: write_struct 1@ offset 0x13 size 1 value 1 //0xBC6 = [byte] Free Slot 2
return

:PickUp
find = 0
while 0EA9: get_any_object_no_save_recursive find progress_to find object_to Obj
    0984: 1@ = object Obj model
    if and
        1@ >= 321 // 
        1@ <= 372 // 
        0EE6: locate_char_distance_to_object $PLAYER_ACTOR object Obj radius 1.5
    then
        0A98: 1@ = Obj objstruct
        0D4E: 3@ = struct 1@ offset 0x11 size 2 //0xBC4 = [word] Free Slot 1
        0D4E: 4@ = struct 1@ offset 0x13 size 1 //0xBC6 = [byte] Free Slot 2
        if and
            3@ > 1
            4@ > 0
        then

            if
                0AB0:   is_key_pressed Key_3
            then
            
                03E6: remove_text_box
                repeat
                wait 0
                04ED: load_animation  "DropWeapons"
                until 04EE:   animation "DropWeapons" loaded
            
                0A1A: actor $PLAYER_ACTOR perform_walk_animation "PickWeapons" IFP "DropWeapons" framedelta 8.0 loopA 0 lockX 0 lockY 0 lockF 0 -1 ms // versionC
                0655: AS_ped $PLAYER_ACTOR look_at_object Obj 1000 ms
                04EF: release_animation "DropWeapons"
            
                if
                    03CA:   object Obj exists
                then
                    0984: 1@ = Obj object_model
                    0AA7: call_function 0x00454AE0 num_params 1 pop 1 _ModelId 1@ _WeaponForModel 2@ //0x00454AE0 this address found by me DavidStrs not true then why no one used it ?
                end
            
                wait 400
            
                if
                    03CA:   object Obj exists
                then
                    01B2: give_actor $PLAYER_ACTOR weapon 2@ ammo 3@ // Load the weapon model before using this
                    0108: destroy_object Obj
                end
            
                wait 200
            end
        end
    end
end
return

:Ped_Weapon
find = 0
while get_any_char_no_save_recursive find progress_to find char_to Ped_bone
    0470: 1@ = actor Ped_bone current_weapon
    if and
        8118:   not actor Ped_bone dead
        80DF:   not actor Ped_bone driving
        803B:   not $PLAYER_ACTOR == Ped_bone  // (int)
        1@ > 0 //     
        not is_char_script_controlled Ped_bone
    then

        4@ = false //  

        if
            003B:   Ped_bone == Ped_damage  // (int)
        then
            if
                Bone_1 == 6
            then
                if
                    0E4D: random_percent Percent_hand_drop
                then
                    if or
                        0611:   actor Ped_bone performing_animation "DAM_armR_frmBK"
                        0611:   actor Ped_bone performing_animation "DAM_armR_frmFT"
                        0611:   actor Ped_bone performing_animation "DAM_armR_frmRT"
                        0611:   actor Ped_bone performing_animation "SHOT_leftP"
                        0611:   actor Ped_bone performing_animation "SHOT_partial"
                    then
                        if 0611:   actor Ped_bone performing_animation "DAM_armR_frmBK"
                        then 0613: 1@ = actor Ped_bone animation "DAM_armR_frmBK" time
                        end
                        if 0611:   actor Ped_bone performing_animation "DAM_armR_frmFT"
                        then 0613: 1@ = actor Ped_bone animation "DAM_armR_frmFT" time
                        end
                        if 0611:   actor Ped_bone performing_animation "DAM_armR_frmRT"
                        then 0613: 1@ = actor Ped_bone animation "DAM_armR_frmRT" time
                        end
                        if 0611:   actor Ped_bone performing_animation "SHOT_leftP"
                        then 0613: 1@ = actor Ped_bone animation "SHOT_leftP" time
                        end
                        if 0611:   actor Ped_bone performing_animation "SHOT_partial"
                        then 0613: 1@ = actor Ped_bone animation "SHOT_partial" time
                        end
                        if and
                            1@ > 0.2
                            1@ < 0.7
                        then
                            4@ = true
                        end
                    end
                else
                    0467: clear_actor Ped_bone last_weapon_damage
                    054E: clear_actor Ped_bone damage
                    wait 300
                    break
                end
            end
        end

        if
            4@ == true
        then
            0AAA: 1@ = get_script_struct_named 'DropQA'
            if
                1@ == 0
            then
                0A92: stream_custom_script "Drop Weapons Peds.qa" Ped_bone Mode
                wait 500
                break
            end
        end

    end
end
return


:Damage
if
    0E46: is_char_using_gun $PLAYER_ACTOR
then
    0470: 1@ = actor Ped_damage current_weapon
    if and
        8118:   not actor Ped_damage dead
        80DF:   not actor Ped_damage driving
        803B:   not $PLAYER_ACTOR == Ped_damage  // (int)
        1@ > 0 //     
        not is_char_script_controlled Ped_damage
    then
        get_char_damage_last_frame Ped_damage damager Damager_1 type Type_1 part Bone_1 intensity Intensity_1   // type = gun int, part = bone char int, intensity = damage float
    end
end
return_script_event
